import * as THREE from 'three'
import { createFanShape } from './fanShape.js'

/**
 * 将两个扇形组合成一个完整的静态扫描形状
 * @param {Object} options 配置项
 * @param {THREE.Object3D} options.object3d  扫描形状要添加的物体
 * @param {Number} options.radius 扇形半径
 * @param {Number} [options.x = 0]  右侧扇形相对于添加到的物体的x坐标,默认为0
 * @param {Number} [options.y=0] 右侧扇形相对于添加到的物体的y坐标,默认为0
 * @param {Number} [options.z=0] 右侧扇形相对于添加到的物体的z坐标,默认为0
 * @param {String} [options.name='scanEffect'] 扫描形状的name,默认为'scanEffect'
 * @param {Array} [options.groupArr] 用与管理扫描效果的数组,可选
 * @return {THREE.Group} 返回一个包含两个扇形对象的组
 */
export const createScanEffect = ({
  object3d,
  radius,
  x = 0,
  y = 0,
  z = 0,
  name = 'scanEffect',
  groupArr,
} = {}) => {
  const leftFan = createFanShape(radius, 0x00ffff)
  const rightFan = createFanShape(radius, 0x00ffff)
  // 设置位置和旋转
  rightFan.position.set(x, y, z)
  leftFan.position.set(-x, y, z)
  leftFan.rotateY(Math.PI)

  // 添加到物体并隐藏
  const group = new THREE.Group()
  group.add(leftFan, rightFan)
  object3d.add(group)
  group.name = name
  group.visible = false
  groupArr?.push(group)
  return group
}
